﻿using EmoneyWeiXinBLL;
using EmoneyWeiXinCommon;
using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EmoneyWeiXin.Controllers
{
    public class NewsController : Controller
    {
        //
        // GET: /News/

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 名家解盘
        /// </summary>
        /// <returns></returns>
        public ActionResult Mjjp()
        {
            string meid = "";
            string openId = "";
            if (Request["meid"] != null) meid = Request["meid"].ToString();
            if (Request["openid"] != null)
            {
                openId = Request["openid"];
            }
            ViewBag.openid = openId;
            ViewBag.key = meid;
            NewsReportManager bll = new NewsReportManager();
            ViewBag.lday = bll.getList_date(Convert.ToInt32(meid)).ToString("yyyy-MM-dd");
            return View();
        }

        public string getPubNewsByDay()
        {
            string meid = "";
            if (Request["meid"] != null) meid = Request["meid"].ToString();
            string day = "";
            if (Request["day"] != null) day = Request["day"].ToString();
            string pre = "1";
            if (Request["pre"] != null) pre = Request["pre"].ToString();

            int aa = 10;
            if (Request["size"] != null)
            {
                if (!Int32.TryParse(Request["size"].ToString(), out aa))
                {
                    aa = 10;
                }
            }
            int bb = 0;
            if (Request["index"] != null)
            {
                if (!Int32.TryParse(Request["index"].ToString(), out bb))
                {
                    bb = 0;
                }
            }
            NewsReportManager bll = new NewsReportManager();
            var list = bll.getNewsForClientDayByDay(meid, day, Convert.ToInt32(pre));
            return JsonTools.ToJson(list);
        }


        public ActionResult JiQiao()
        {
            string meid = "";
            if (Request["meid"] != null) meid = Request["meid"].ToString();
            string subid = "";
            if (Request["subid"] != null) subid = Request["subid"].ToString();

            int weiXinId = 0;
            if (Request["weixinId"] != null)
            {
                weiXinId = int.Parse(Request["weixinId"]);
            }

            try
            {
                MenuBLL bll = new MenuBLL();
                IList<MenuEntity> mlist = MenuBLL.getMenuChildrenList(Convert.ToInt32(meid), weiXinId);
                ViewBag.menus = mlist;
                if (subid == "")
                {
                    if (mlist.Count > 0)
                    {
                        subid = mlist[0].id.ToString();
                    }
                }
                ViewBag.active = subid;
                ViewBag.openid = Request["openid"] == null ? "" : Request["openid"];

            }
            catch (Exception ex)
            {

                //  return Redirect("~/Error.aspx?refer=" + System.Web.HttpUtility.UrlEncode(Request.Url.AbsoluteUri) + "&msg=" + ex.Message);
            }
            return View();
        }


        public string GetNewsList()
        {
            string meid = "";
            if (Request["meid"] != null) meid = Request["meid"].ToString();
            int size = 0;
            if (Request["size"] != null) size = Convert.ToInt32(Request["size"]);
            int index = 0;
            if (Request["index"] != null) index = Convert.ToInt32(Request["index"]);

            NewsReportManager bll2 = new NewsReportManager();
            IList<NewsReportEntity> nlist = bll2.getNewsForClient2(meid, false, size, index);
            return JsonTools.ToJson(nlist);
        }



    }
}
